package com.ruoyi.crm.sale.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.crm.sale.domain.CrmClue;
import com.ruoyi.crm.sale.service.ICrmClueService;

/**
 * 线索管理Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/crm/clue")
public class CrmClueController extends BaseController
{
    @Autowired
    private ICrmClueService crmClueService;

    /**
     * 查询线索管理列表
     */
    @PreAuthorize("@ss.hasPermi('crm:clue:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmClue crmClue)
    {
        startPage();
        List<CrmClue> list = crmClueService.selectCrmClueList(crmClue);
        return getDataTable(list);
    }

    /**
     * 导出线索管理列表
     */
    @PreAuthorize("@ss.hasPermi('crm:clue:export')")
    @Log(title = "线索管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmClue crmClue)
    {
        List<CrmClue> list = crmClueService.selectCrmClueList(crmClue);
        ExcelUtil<CrmClue> util = new ExcelUtil<CrmClue>(CrmClue.class);
        return util.exportExcel(list, "线索管理数据");
    }

    /**
     * 获取线索管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:clue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmClueService.selectCrmClueById(id));
    }

    /**
     * 线索转客户
     */
    @PreAuthorize("@ss.hasPermi('crm:clue:query')")
    @GetMapping(value = "/clueToCustomer/{id}")
    public AjaxResult clueToCustomer(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmClueService.clueToCustomer(id));
    }

    /**
     * 新增线索管理
     */
    @PreAuthorize("@ss.hasPermi('crm:clue:add')")
    @Log(title = "线索管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmClue crmClue)
    {
        return toAjax(crmClueService.insertCrmClue(crmClue));
    }

    /**
     * 修改线索管理
     */
    @PreAuthorize("@ss.hasPermi('crm:clue:edit')")
    @Log(title = "线索管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmClue crmClue)
    {
        return toAjax(crmClueService.updateCrmClue(crmClue));
    }

    /**
     * 删除线索管理
     */
    @PreAuthorize("@ss.hasPermi('crm:clue:remove')")
    @Log(title = "线索管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmClueService.deleteCrmClueByIds(ids));
    }
}
